<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>我的评论</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap/js/bootstrap.min.js"></script>
    <script src="/js/plugins/jrender/jrender.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css">
    <link rel="stylesheet" href="/js/plugins/dialog/dialog.css">
    <link rel="stylesheet" href="/css/reset.css">
    <link rel="stylesheet" href="/css/userProfiles.css">
    <link rel="stylesheet" href="/js/plugins/jquery-confirm/css/jquery-confirm.css">
    <script src="/js/plugins/jquery-confirm/js/jquery-confirm.js"></script>
    <script src="/js/plugins/dialog/dialog.min.js"></script>
    <script src="/js/common.js"></script>
    <script>
        var currentPage = 1;
        var pages;
        var comments;
        $(function () {
            //拿到当前登录用户
            var user = sessionStorage.getItem("user");
            user = JSON.parse(user);
            $.get("/users/" + user.id + "/comment", {currentPage: 1, pageSize: 5}, function (data) {
                //渲染点评
                renderView(data);
                pages = data.pages;
                comments = data.list;
            });
            //设置窗口的滚到事件
            $(window).scroll(function () {
                if ($(document).scrollTop() + $(window).height() >= $(document).height() - 28) {
                    if (currentPage < pages) {
                        currentPage++;
                        $.get("/users/" + user.id + "/comment", {
                            currentPage: currentPage,
                            pageSize: 5
                        }, function (data) {
                            //数据渲染
                            $.merge(comments, data.list);
                            renderView({list: comments});
                        });
                    } else {
                        $(document).dialog({
                            type: "notice",
                            infoText: "就这么多啦  (*￣3￣)╭",
                            autoClose: 1500,
                            position: "bottom"
                        });
                    }
                }
            });
        })

        function renderView(data) {
            $("#comments").renderValues(data, {
                handle: function (ele, value) {
                    ele.href = "/strategyComment.html?id=" + value;
                },
                star: function (ele, value) {
                    $(ele).attr("star", value);
                },
                strategy: function (ele, value) {
                    ele.href = "strategyCatalogs.html?strategyId=" + value;
                }
            });
            //渲染小星星
            var stars = $(".comment-star");
            $.each(stars, function (index, ele) {
                var star = $(ele);
                var num = star.attr("star");
                for (var i = 0; i < num; i++) {
                    $("<i class=\"fa fa-star\"></i>").appendTo(star);
                }
                for (var i = 0; i < 5 - num; i++) {
                    $("<i class=\"fa fa-star-o\"></i>").appendTo(star);
                }
            })

        }
    </script>
</head>
<body>
<div class="search-head">
    <div class="row nav-search" style="background-color: #6c757d">
        <div class="col-4">
            <a href="javascript:window.history.go(-1)">
                <span><i class="fa fa-chevron-left fa-2x"></i></span>
            </a>
        </div>
        <div class="col-8">
            <div class="input-group-sm search">
                <h5 style="color: #e9ecef">我的评论</h5>
            </div>
        </div>
    </div>
</div>


<div class="comment tab-pane" id="comments">
    <div render-loop="list">
        <div class="row">
            <div class="col-2 comment-head">
                <img class="rounded-circle" render-src="list.user.headImgUrl">
            </div>
            <div class="col">
                        <span class="comment-star" render-key="list.level" render-fun="star">
                            <!--小星星-->
                        </span>

                <span class="comment-date" render-html="list.time"></span>
                <div class="comment-content">
                    <a render-key="list.id" render-fun="handle">
                        <p render-html="list.commentText"></p>
                    </a>
                </div>
                <ul class="comment-img" render-loop="list.imgUrls">
                    <li>
                        <img render-src="list.imgUrls.imgUrl">
                    </li>
                </ul>

                <div class="comment-link">
                    <a render-key="list.strategyId" render-fun="strategy">
                        <img render-src="list.strategyImg"> <span render-html="list.strategyTitle"></span>
                        <i class="fa fa-angle-right fa-2x"></i>
                    </a>
                </div>
            </div>
        </div>
    </div>
</div>

<div id="push"></div>
</body>
</html>